{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "#spacy specify each entity as one of the following :\n",
    "\n",
    "# PERSON:      People, including fictional.\n",
    "# NORP:        Nationalities or religious or political groups.\n",
    "# FAC:         Buildings, airports, highways, bridges, etc.\n",
    "# ORG:         Companies, agencies, institutions, etc.\n",
    "# GPE:         Countries, cities, states.\n",
    "# LOC:         Non-GPE locations, mountain ranges, bodies of water.\n",
    "# PRODUCT:     Objects, vehicles, foods, etc. (Not services.)\n",
    "# EVENT:       Named hurricanes, battles, wars, sports events, etc.\n",
    "# WORK_OF_ART: Titles of books, songs, etc.\n",
    "# LAW:         Named documents made into laws.\n",
    "# LANGUAGE:    Any named language.\n",
    "# DATE:        Absolute or relative dates or periods.\n",
    "# TIME:        Times smaller than a day.\n",
    "# PERCENT:     Percentage, including ”%“.\n",
    "# MONEY:       Monetary values, including unit.\n",
    "# QUANTITY:    Measurements, as of weight or distance.\n",
    "# ORDINAL:     “first”, “second”, etc.\n",
    "# CARDINAL:    Numerals that do not fall under another type."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "pip install spacy\n",
    "pip install nltk\n",
    "\n",
    "#run in console\n",
    "#python -m spacy download en_core_web_sm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import spacy \n",
    "from langchain_community.document_loaders import PyPDFLoader\n",
    "\n",
    "#en_core_web_sm is a pre-trained small English language model for spaCy, trained on a massive amount of English text data\n",
    "ner = spacy.load(\"en_core_web_sm\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#pdf 1 - Harry Potter and the Death Hallows Summary.pdf\n",
    "from spacy import displacy\n",
    "\n",
    "loader = PyPDFLoader('../data/Harry Potter and the Death Hallows Summary.pdf')\n",
    "pages = loader.load_and_split()\n",
    "\n",
    "contents=''\n",
    "for i in range(0,len(pages)):\n",
    "    contents=' '.join([contents,pages[i].page_content.replace('\\n',' ')])\n",
    "\n",
    "doc = ner(contents) \n",
    "displacy.render(doc, style=\"ent\")   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#pdf 2 - About Amazon.pdf\n",
    "\n",
    "from spacy import displacy\n",
    "\n",
    "loader = PyPDFLoader('../data/About Amazon.pdf')\n",
    "pages = loader.load_and_split()\n",
    "\n",
    "contents=''\n",
    "for i in range(0,len(pages)):\n",
    "    contents=' '.join([contents,pages[i].page_content.replace('\\n',' ')])\n",
    "\n",
    "doc = ner(contents) \n",
    "displacy.render(doc, style=\"ent\") "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#pdf 3 - Apple stock during pandemic.pdf\n",
    "\n",
    "from spacy import displacy\n",
    "\n",
    "loader = PyPDFLoader('../data/Apple stock during pandemic.pdf')\n",
    "pages = loader.load_and_split()\n",
    "\n",
    "contents=''\n",
    "for i in range(0,len(pages)):\n",
    "    contents=' '.join([contents,pages[i].page_content.replace('\\n',' ')])\n",
    "\n",
    "doc = ner(contents) \n",
    "displacy.render(doc, style=\"ent\") "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#pdf 4 - Bank of America Q23.pdf\n",
    "\n",
    "from spacy import displacy\n",
    "\n",
    "loader = PyPDFLoader('../data/Bank of America Q23.pdf')\n",
    "pages = loader.load_and_split()\n",
    "\n",
    "contents=''\n",
    "for i in range(0,len(pages)):\n",
    "    contents=' '.join([contents,pages[i].page_content.replace('\\n',' ')])\n",
    "\n",
    "doc = ner(contents) \n",
    "displacy.render(doc, style=\"ent\") "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.0.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
